local ls = require("luasnip")
local s = ls.snippet
local sn = ls.snippet_node
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
local d = ls.dynamic_node
local fmt = require("luasnip.extras.fmt").fmt
local fmta = require("luasnip.extras.fmt").fmta
local rep = require("luasnip.extras").rep
local isn = ls.indent_snippet_node

ls.add_snippets("php",{
  -- html
  s("br", fmt([[
  <br />{}
]], {
    i(1),
  })),
  s("hr", fmt([[
  <hr />{}
]], {
    i(1),
  })),
  -- PHP
  s("php", fmt([[
<?php {} ?>
]], {
    i(1),
  })),
  -- PHP Echo
  s("ec", fmt([[
echo {};
]], {
    i(1),
  })),
  -- PHP
  s("php", fmt([[
<?php
  {}
?>
]], {
    i(1),
  })),
  -- PHP declare
  s("phpt", fmt([[
<?php
declare(strict_types=1); // 严格模式
{}
?>
]], {
    i(1),
  })),
  -- PHP Class Definition
  s("class", fmt([[
class {} {{
  {}
}}]], {
    i(1, "ClassName"),
    i(2),
  })),

  -- PHP Function
  s("fun", fmt([[
function {}({}) {{
  {}
}}]], {
    i(1, "functionName"),
    i(2),
    i(3)
  })),

  -- PHP Constructor
  s("__con", fmt([[
public function __construct({}) {{
  {}
}}]], {
    i(1),
    i(2)
  })),

  -- PHP Interface
  s("interface", fmt([[
<?php

interface {} {{
  {}
}}]], {
    i(1, "InterfaceName"),
    i(2)
  })),

  -- PHP Trait
  s("trait", fmt([[
<?php

trait {} {{
  {}
}}]], {
    i(1, "TraitName"),
    i(2)
  })),

  -- PHP Array
  s("arr", fmt("${} = [{}]", {
    i(1, "array"),
    i(2)
  })),

  -- PHP foreach loop
  s("fore", fmt([[
foreach (${} as ${}) {{
  {}
}}]], {
    i(1, "array"),
    i(2, "value"),
    i(3)
  })),

  -- PHP foreach with key
  s("forek", fmt([[
foreach (${} as ${} => ${}) {{
  {}
}}]], {
    i(1, "array"),
    i(2, "key"),
    i(3, "value"),
    i(4)
  })),

  -- PHP if statement
  s("if", fmt([[
if ({}) {{
  {}
}}]], {
    i(1, "condition"),
    i(2)
  })),

  -- PHP try-catch
  s("try", fmt([[
try {{
  {}
}} catch ({} ${}) {{
  {}
}}]], {
    i(1),
    i(2, "Exception"),
    i(3, "e"),
    i(4)
  })),

  -- PHP variable dump
  s("vd", fmt("var_dump({});", {
    i(1)
  })),

  -- PHP print_r
  s("pr", fmt("print_r({});", {
    i(1)
  })),

  -- PHP namespace
  s("ns", fmt("namespace {};", {
    i(1, "Namespace")
  })),

  -- PHP use statement
  s("use", fmt("use {};", {
    i(1, "Namespace\\Class")
  })),

  -- PHP getter
  s("get", fmt([[
public function get{}() {{
  return $this->{};
}}]], {
    i(1, "PropertyName"),
    rep(1)
  })),

  -- PHP setter
  s("set", fmt([[
public function set{}(${}) {{
  $this->{} = ${};
  return $this;
}}]], {
    i(1, "PropertyName"),
    i(2, "value"),
    rep(1),
    rep(2)
  })),

})
